package com.ssii.www.myproject.common.util;


import com.ssii.www.myproject.domain.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;

public class UserContext {
  //封装这个类用来设置和得到 可以从全局得到的登陆用户‘对象’
  private static final String LOGINUSER = "loginUser";
  //设置
  public static void setUser(User user){
    Subject subject = SecurityUtils.getSubject();
    Session session = subject.getSession();
    session.setAttribute(LOGINUSER,user);
  }
  //得到
  public static User getUser(){
    Subject subject = SecurityUtils.getSubject();
    Session session = subject.getSession();
    User user = (User) session.getAttribute(LOGINUSER);
    return user;
  }
}
